﻿/* ================================================================================
<copyright file="frmConnect.cs" company="The Framework Factory, LLC" lastWriteTime="12/05/2012 23:23:47 PM">
  Copyright (c) 2012 The Framework Factory, LLC.  All rights reserved.
</copyright>
=================================================================================== */
using System;
using System.Runtime.Remoting;
using System.Windows.Forms;

using FWF.Logging.Net;

namespace FWF.Logging.Viewer
{
    /// <summary>
    /// 
    /// </summary>
    public partial class frmConnect : Form
    {

        #region Constructors / Finalizer

        /// <summary>
        /// Initializes a new instance of the <see cref="frmConnect"/> class.
        /// </summary>
        public frmConnect()
        {
            InitializeComponent();
        }

        #endregion

        /// <summary>
        /// Handles the Load event of the frmConnect control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void frmConnect_Load( object sender, EventArgs e )
        {
            txtConnectionString.Text = "tcp://127.0.0.1:7700/LogPublisher";
        }

        /// <summary>
        /// Handles the Click event of the btnConnect control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnConnect_Click( object sender, EventArgs e )
        {
            try
            {
                //
                var publisherUrl = new Uri( txtConnectionString.Text );

                //
                LogSubscriber.Connect( publisherUrl );

                DialogResult = DialogResult.OK;
                Close();
            }
            catch ( Exception ex )
            {
                MessageBox.Show( this, "Invalid connection string: " + ex.Message );
            }
        }

    }
}
